let agcimLayerLoader = agcim.scene.layerLoader;
class SplitScreen {
    constructor() {
        this._aglayers = [];
        this._aglayerIds = [];
        this._layerTree = new agcim.scene.LayerTree(CIM.secondViewer);
    }
    /**
     * @description: 分屏
     * @param {*} node 
     */
    splitScreen(node) {
        if (!node.splitScreen) {
            node.splitScreen = true;
            this.addSplitScreen(node.id, CIM.secondViewer);
        } else {
            node.splitScreen = false;
            this.removeSplitLayerById(node.id, CIM.secondViewer);
        }
    }
    /************************分屏*************************** */
    /**
     * @description: 添加分屏
     * @param {*} id 
     * @param {*} viewer 
     */
    addSplitScreen(id, viewer) {
        var layer = this.getSplitLayerById(id, viewer);
        if (layer) {
            layer.setVisible(true);
        } else if (CIM.layerTree._layerTreeData[id]) {
            //如果不存在就添加。
            this.addSplitScreenLayer(CIM.layerTree._layerTreeData[id], viewer);
        }
    }
    /**
     * @description: 添加分屏图层
     * @param {*} ly 
     * @param {*} viewer 
     * @returns 
     */
    addSplitScreenLayer(ly, viewer) {
        let type = ly.layerType;
        ly.splitScreen = true;
        let ip = window.origin.replace("http://", "");
        for (let i = 0; i < agcimLayerLoader.length; i++) {
            if (agcimLayerLoader[i].supportTypes.indexOf(type) != -1 && this._layerTree._aglayerIds.indexOf(ly.id) < 0) {
                if (this._layerTree._aglayerIds.indexOf(ly.id) < 0) {
                    this._layerTree._aglayerIds.push(ly.id);
                }
                let layerinfo = {
                    userId: CIM_USER_ID,
                    userName: CIM_USER_NAME,
                    layerId: ly.id,
                    layerUrl: ly.url,
                    layerName: ly.nameCn,
                    serverIp: ip,
                }
                // 处理sdk enableModelExperimental逻辑
                // tips cesium1.95版本enableModelExperimental为true时 副屏加载3dTiles不展示
                ly.baseColor = "";
                agcimLayerLoader[i].add(viewer, ly, this._layerTree);
                return;
            }
        }
    }
    /**
     * @description: 根据id移除分屏图层
     * @param {*} id 
     * @param {*} viewer 
     * @param {*} time 
     * @returns 
     */
    removeSplitLayerById(id, viewer, time = 3000) {
        var layer = this.getSplitLayerById(id, viewer);
        if (layer) {
            layer.setVisible(false);
            return true;
        }
        return false;
    }
    /**
     * @description: 根据id获取分屏图层
     * @param {*} id 
     * @param {*} viewer 
     * @returns 
     */
    getSplitLayerById(id, viewer) {
        for (let i = 0; i < this._layerTree._aglayers.length; i++) {
            if (this._layerTree._aglayers[i].id == id && this._layerTree._aglayers[i].viewer == viewer) {
                return this._layerTree._aglayers[i];
            }
        }
    }
}
export default new SplitScreen();